<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<?php
require_once("include.php");
require_once("sorderobj.php");
require_once("class.ezpdf.php");
session_start();
require_once("showmenu.php");
require_once("pdfsorder.php");
//authorise("userinput");
(isset($_REQUEST["restart"])) ? $restart = $_REQUEST["restart"] : $restart = "NULL" ;
(isset($_REQUEST["res"])) ? $res = $_REQUEST["res"] : $res = "NULL" ;
(isset($_REQUEST["sub"])) ? $sub = $_REQUEST["sub"] : $sub = "NULL" ;
(isset($_REQUEST["itemid"])) ? $itemid = $_REQUEST["itemid"] : $itemid = "NULL" ;
unset($_SESSION["sledger_METADATA"]);
if (!(isset($_SESSION["sorder"]))) {$obj = new sorder();}
$obj=&$_SESSION["sorder"] ;
if ($obj->header[2] !== "") {
 // have already read or created an item
 $obj->applyfromrequest();

 if ($sub == "Save" && $obj->valid) {
  $obj->writedb();
  $obj->confirmfiled($_SESSION["lastid"]);
 } elseif ($sub == "Print" && $obj->valid) {
  echo $obj->makehtml();
  $obj->writedb();
  $obj->localprint();
 } elseif ($sub == "Email" && $obj->valid) {
  $obj->emailpdf();
  $obj->writedb();
 } elseif($res=="restart") {
  unset($_SESSION[$obj->gettablename()]);
 } elseif($sub == "Abandon Changes") {
  $obj->showform();  
 } else {
  // Default is apply button, or might be refresh/back etc.
  $obj->showform();
 }
} elseif ($itemid=="") {
 // request to set up a new item
 $obj->createblank();
 $obj->showform();
} elseif ($itemid == "NULL") {
 // First call to routine
 $obj->showchoose();
} else {
 // try reading the specific item. We have been supplied with an itemid
 if ($obj->readdb($itemid)) {
  $obj->showform();
 } else {
  $obj->showchoose();
 } 
}
?>